#include <windows.h>
#include <cstring>

LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);

HWND hWnd;
HWND hwndEmployer1NameLabel;
HWND hwndEmployer1NameEdit;
HWND hwndEmployer1YearsLabel;
HWND hwndEmployer1YearsEdit;
HWND hwndEmployer1SalaryLabel;
HWND hwndEmployer1SalaryEdit;
HWND hwndEmployer2NameLabel;
HWND hwndEmployer2NameEdit;
HWND hwndEmployer2YearsLabel;
HWND hwndEmployer2YearsEdit;
HWND hwndEmployer2SalaryLabel;
HWND hwndEmployer2SalaryEdit;
HWND hwndEmployer3NameLabel;
HWND hwndEmployer3NameEdit;
HWND hwndEmployer3YearsLabel;
HWND hwndEmployer3YearsEdit;
HWND hwndEmployer3SalaryLabel;
HWND hwndEmployer3SalaryEdit;
HWND hwndHighestButton;
HWND hwndLowestButton;
HWND hwndLongestButton;
HWND hwndShortestButton;
HWND hwndMessage;
char szEmployer1Name[50];
char szEmployer2Name[50];
char szEmployer3Name[50];
char szEmployer1Years[5];
char szEmployer2Years[5];
char szEmployer3Years[5];
char szEmployer1Salary[10];
char szEmployer2Salary[10];
char szEmployer3Salary[10];
double dEmployer1Years;
double dEmployer2Years;
double dEmployer3Years;
double dEmployer1Salary;
double dEmployer2Salary;
double dEmployer3Salary;
char szResponse[50];

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
	LPSTR lpCmdLine, int nCmdShow) {

	WNDCLASS wc;

	wc.lpszClassName = "JobHistory";
	wc.lpfnWndProc = MainWndProc;
	wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
	wc.hCursor = LoadCursor( NULL, IDC_ARROW );
	wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
	wc.lpszMenuName = "";
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	RegisterClass( &wc );

	hWnd = CreateWindow(
		"JobHistory", "Job History",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		300,
		450,
		NULL,
		NULL,
		hInstance,
		NULL);

	hwndEmployer1NameLabel = CreateWindow( 
		"Static", 
		"Employer 1 name", 
		WS_VISIBLE | WS_CHILD,
		10,
		10, 
		130, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer1NameEdit = CreateWindow( 
		"EDIT", 
		NULL, 
		WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
		140,
		10, 
		140, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer1YearsLabel = CreateWindow( 
		"Static", 
		"Employer 1 years", 
		WS_VISIBLE | WS_CHILD,
		10,
		35, 
		130, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer1YearsEdit = CreateWindow( 
		"EDIT", 
		NULL, 
		WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
		140,
		35, 
		140, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer1SalaryLabel = CreateWindow( 
		"Static", 
		"Employer 1 pay", 
		WS_VISIBLE | WS_CHILD,
		10,
		60, 
		130, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer1SalaryEdit = CreateWindow( 
		"EDIT", 
		NULL, 
		WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
		140,
		60, 
		140, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer2NameLabel = CreateWindow( 
		"Static", 
		"Employer 2 name", 
		WS_VISIBLE | WS_CHILD,
		10,
		100, 
		130, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer2NameEdit = CreateWindow( 
		"EDIT", 
		NULL, 
		WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
		140,
		100, 
		140, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer2YearsLabel = CreateWindow( 
		"Static", 
		"Employer 2 years", 
		WS_VISIBLE | WS_CHILD,
		10,
		125, 
		130, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer2YearsEdit = CreateWindow( 
		"EDIT", 
		NULL, 
		WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
		140,
		125, 
		140, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer2SalaryLabel = CreateWindow( 
		"Static", 
		"Employer 2 pay", 
		WS_VISIBLE | WS_CHILD,
		10,
		150, 
		130, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer2SalaryEdit = CreateWindow( 
		"EDIT", 
		NULL, 
		WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
		140,
		150, 
		140, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer3NameLabel = CreateWindow( 
		"Static", 
		"Employer 3 name", 
		WS_VISIBLE | WS_CHILD,
		10,
		190, 
		130, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer3NameEdit = CreateWindow( 
		"EDIT", 
		NULL, 
		WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
		140,
		190, 
		140, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer3YearsLabel = CreateWindow( 
		"Static", 
		"Employer 3 years", 
		WS_VISIBLE | WS_CHILD,
		10,
		215, 
		130, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer3YearsEdit = CreateWindow( 
		"EDIT", 
		NULL, 
		WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
		140,
		215, 
		140, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer3SalaryLabel = CreateWindow( 
		"Static", 
		"Employer 3 pay", 
		WS_VISIBLE | WS_CHILD,
		10,
		240, 
		130, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndEmployer3SalaryEdit = CreateWindow( 
		"EDIT", 
		NULL, 
		WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
		140,
		240, 
		140, 
		20, 
		hWnd,
		NULL, 
		hInstance, 
		NULL); 

	hwndHighestButton = CreateWindow( 
		"BUTTON",
		"Highest Salary", 
		WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
		10,
		275, 
		270, 
		25, 
		hWnd, 
		NULL, 
		hInstance, 
		NULL); 

	hwndLowestButton = CreateWindow( 
		"BUTTON",
		"Lowest Salary", 
		WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
		10,
		300, 
		270, 
		25, 
		hWnd, 
		NULL, 
		hInstance, 
		NULL); 

	hwndLongestButton = CreateWindow( 
		"BUTTON",
		"Longest Employment", 
		WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
		10,
		325, 
		270, 
		25, 
		hWnd, 
		NULL, 
		hInstance, 
		NULL); 

	hwndShortestButton = CreateWindow( 
		"BUTTON",
		"Shortest Employment", 
		WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
		10,
		350, 
		270, 
		25, 
		hWnd, 
		NULL, 
		hInstance, 
		NULL); 

	hwndMessage = CreateWindow( 
		"STATIC",
		NULL, 
		WS_VISIBLE | WS_CHILD,
		10,
		385, 
		270, 
		25, 
		hWnd, 
		NULL, 
		hInstance, 
		NULL); 

	ShowWindow(hWnd, nCmdShow);

	MSG msg;
	while(GetMessage(&msg, NULL, 0, 0 )) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return (int) msg.wParam;
}


LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, 
	WPARAM wParam, LPARAM lParam) {
	HWND hwndCtl = (HWND) lParam;
	switch (msg) {
		case WM_COMMAND:
			switch (wParam) {
				case BN_CLICKED:

				GetWindowText(hwndEmployer1NameEdit, szEmployer1Name, 50);
				GetWindowText(hwndEmployer1YearsEdit, szEmployer1Years, 10);
				GetWindowText(hwndEmployer1SalaryEdit, szEmployer1Salary, 10);
				GetWindowText(hwndEmployer2NameEdit, szEmployer2Name, 50);
				GetWindowText(hwndEmployer2YearsEdit, szEmployer2Years, 10);
				GetWindowText(hwndEmployer2SalaryEdit, szEmployer2Salary, 10);
				GetWindowText(hwndEmployer3NameEdit, szEmployer3Name, 50);
				GetWindowText(hwndEmployer3YearsEdit, szEmployer3Years, 10);
				GetWindowText(hwndEmployer3SalaryEdit, szEmployer3Salary, 10);
				dEmployer1Years = atof(szEmployer1Years);
				dEmployer2Years = atof(szEmployer2Years);
				dEmployer3Years = atof(szEmployer3Years);
				dEmployer1Salary = atof(szEmployer1Salary);
				dEmployer2Salary = atof(szEmployer2Salary);
				dEmployer3Salary = atof(szEmployer3Salary);

					if (hwndCtl == hwndHighestButton) {
						if (dEmployer1Salary > dEmployer2Salary && 
                        dEmployer1Salary > dEmployer3Salary) 
                        {
							strcpy(szResponse, szEmployer1Name);
							strcat(szResponse, 
                                                        " paid you the highest salary");
						}
						else if (dEmployer2Salary > dEmployer1Salary && 
                        dEmployer2Salary > dEmployer3Salary) 
                        {
							strcpy(szResponse, szEmployer2Name);
							strcat(szResponse, 
                                                        " paid you the highest salary");
						}
						else if (dEmployer3Salary > dEmployer1Salary && 
                        dEmployer3Salary > dEmployer2Salary) 
                        {
							strcpy(szResponse, szEmployer3Name);
							strcat(szResponse, 
                                                        " paid you the highest salary");
						}
					}
					else if (hwndCtl == hwndLowestButton) {
						if (dEmployer1Salary < dEmployer2Salary && 
                        dEmployer1Salary < dEmployer3Salary) 
                        {
							strcpy(szResponse, szEmployer1Name);
							strcat(szResponse, 
                                                        " paid you the lowest salary");
						}
						else if (dEmployer2Salary < dEmployer1Salary && 
                        dEmployer2Salary < dEmployer3Salary) 
                        {
							strcpy(szResponse, szEmployer2Name);
							strcat(szResponse, 
                                                        " paid you the lowest salary");
						}
						else if (dEmployer3Salary < dEmployer1Salary && 
                        dEmployer3Salary < dEmployer2Salary) 
                        {
							strcpy(szResponse, szEmployer3Name);
							strcat(szResponse, 
                                                        " paid you the lowest salary");
						}
					}
					else if (hwndCtl == hwndLongestButton) 
                    {
						if (dEmployer1Years > dEmployer2Years && 
                        dEmployer1Years > dEmployer3Years) 
                        {
							strcpy(szResponse, szEmployer1Name);
							strcat(szResponse, 
                                                        " was your longest employer");
						}
						else if (dEmployer2Years > dEmployer1Years && 
                        dEmployer2Years > dEmployer3Years) 
                        {
							strcpy(szResponse, szEmployer2Name);
							strcat(szResponse, 
                                                        " was your longest employer");
						}
						else if (dEmployer3Years > dEmployer1Years && 
                        dEmployer3Years > dEmployer2Years) 
                        {
							strcpy(szResponse, szEmployer3Name);
							strcat(szResponse, 
                                                        " was your longest employer");
						}
					}
					else if (hwndCtl == hwndShortestButton) 
                    {
						if (dEmployer1Years < dEmployer2Years && 
                            dEmployer1Years < dEmployer3Years) 
                            {
							strcpy(szResponse, szEmployer1Name);
							strcat(szResponse, 
                                                        " was your shortest employer");
		     				}
						else if (dEmployer2Years < dEmployer1Years && 
                                 dEmployer2Years < dEmployer3Years) 
                            {
							strcpy(szResponse, szEmployer2Name);
							strcat(szResponse, 
                                                        " was your shortest employer");
						    }
						else if (dEmployer3Years < dEmployer1Years && 
                                 dEmployer3Years < dEmployer2Years) 
                            {
							strcpy(szResponse, szEmployer3Name);
							strcat(szResponse, 
                                                        " was your shortest employer");
						    }
					}
			}
			SetWindowText(hwndMessage, szResponse);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
		default:
			return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}

